#include "console.h"
void Console::print_char(char c, int x, int y, int color){
	if (use_colors)
		attron(COLOR_PAIR(color));
	mvaddch(x, y, c);
	if (use_colors)
		attroff(COLOR_PAIR(color));
	//cout<<"print char "<<c<<" at "<<x<<"x"<<y<<endl;
};

void Console::print_string(string s, int x, int y, int color){
	if (use_colors)
		attron(COLOR_PAIR(color));
	mvprintw(y, x, s.c_str());
	if (use_colors)
		attroff(COLOR_PAIR(color));
	//cout<<"print string \""<<s<<"\" at "<<x<<"x"<<y<<endl;
};

void Console::blit(){
	refresh();
	clear();
};

int Console::get_key(){
	return wgetch(stdscr);
};

Console::Console(){
	initscr();
	cbreak();
	keypad(stdscr, TRUE);
	noecho();
	noqiflush();
	//nodelay(); //system is not ready for this
	curs_set(0);
	if(has_colors() != FALSE){
		start_color();
		use_colors=true;
		init_pair(PAIR_SELF, COLOR_SELF, BG_NORMAL);
		init_pair(PAIR_ALLY, COLOR_ALLY, BG_NORMAL);
		init_pair(PAIR_ENEMY, COLOR_ENEMY, BG_NORMAL);
		init_pair(PAIR_NEUTRAL, COLOR_NEUTRAL, BG_NORMAL);
	}
};

Console::~Console(){
	endwin();
};
